tools/oxenstored: Rework Domain evtchn handling to use port_pair
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 30 Nov 2022 11:59:34 +0000 (11:59 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 20 Dec 2022 13:13:40 +0000 (13:13 +0000)
commit4b418768ef4d75d0f70e4ce7cb5710404527bf47
tree30b15f8f5273d30ce7c414443e13d8ab6406359f
parenta20daa7ffda7ccc0e65abe77532a5dc8059bf128
tools/oxenstored: Rework Domain evtchn handling to use port_pair

Inter-domain event channels are always a pair of local and remote ports.
Right now the handling is asymmetric, caused by the fact that the evtchn is
bound after the associated Domain object is constructed.

First, move binding of the event channel into the Domain.make() constructor.
This means the local port no longer needs to be an option.  It also removes
the final callers of Domain.bind_interdomain.

Next, introduce a new port_pair type to encapsulate the fact that these two
should be updated together, and replace the previous port and remote_port
fields.  This refactoring also changes the Domain.get_port interface (removing
an option) so take the opportunity to name it get_local_port instead.

Also, this fixes a use-after-free risk with Domain.close.  Once the evtchn has
been unbound, the same local port number can be reused for a different
purpose, so explicitly invalidate the ports to prevent their accidental misuse
in the future.

This also cleans up some of the debugging, to always print a port pair.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
(cherry picked from commit df2db174b36eba67c218763ef621c67912202fc6)
tools/ocaml/xenstored/connections.ml
tools/ocaml/xenstored/domain.ml
tools/ocaml/xenstored/domains.ml